<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>发码详情</title>
    <link rel="stylesheet" href="common/js/file-input/fileinput.css">
    <link rel="stylesheet" href="common/css/switchery/style.css">
    <link rel="stylesheet" href="common/css/bootstrap.css">
    <link rel="stylesheet" href="common/css/font-awesome.min.css">
    <link rel="stylesheet" href="common/css/style.css">
    <link rel="stylesheet" href="common/css/plugin.css">
    <script src="common/js/jquery-1.11.1.min.js" type="text/javascript"></script>
    <!--[if lt IE 9]>
    <script src="common/js/ie/respond.min.js"></script>
    <script src="common/js/ie/html5.js"></script>
    <![endif]-->
</head>
<body onload="initFamaTab()">
<!-- .modal 发送提示 -->
<div class="modal fade operaState in " data-keyboard="false" id="operaState">
    <div class="modal-dialog modal-sm" style="margin-left:-150px;">
        <div class="modal-content">
            <div class="modal-body pop-div-content">
                <p><i class="icon-success"></i></p>

                <p class="tipP">
                    <label id="promptMsg"></label>
                </p>
            </div>
        </div>
    </div>
</div>
<section class="main padder">
    <div class="clearfix">
        <h4><i class="icon-list"></i>发码详情</h4>
    </div>
    <section class="panel">
        <div class="tab-content">
            <div id="tima" class="tab-pane fade active in">
                <div class="m-t-small">
                    <a href="#" id="allSend" class="btn btn-primary addActivity btn-info" style="display: none">
                        全部短信发送
                    </a>
                    <a href="#" id="allMMSSend" class="btn btn-primary addActivity btn-info" style="display: none">
                        全部彩信发送
                    </a>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <section class="panel">
                            <div class="pull-out">
                                <table class="table table-striped m-b-none" data-ride="datatables">
                                    <thead>
                                    <tr>
                                        <th>商品码</th>
                                        <th>手机号码</th>
                                        <th>发送时间</th>
                                        <th>状态</th>
                                        <th>描述</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </div>
    </section>
</section>


<!-- /.modal 发送提示 -->
<script src="common/js/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="common/js/bootstrap.min.js" type="text/javascript"></script>
<script src="common/js/index.js" type="text/javascript"></script>
<!-- 验证 -->
<script src="common/js/parsley/parsley.js" type="text/javascript"></script>
<!-- checkbox -->
<script src="common/js/fuelux/fuelux.js" type="text/javascript"></script>
<!-- datatables -->
<script src="common/js/datatables/jquery.dataTables10.min.js" type="text/javascript"></script>
<script>
    var url = window.location.search;
    var actId, batchId, tp;
    if (url.lastIndexOf("?") != -1) {
        batchId = url.substring(url.lastIndexOf("?") + 1, url.indexOf("-"));
        actId = url.substring(url.indexOf("-") + 1, url.lastIndexOf("-"));
        tp = url.substring(url.lastIndexOf("-") + 1, url.length);
    }
    var famaTable;
    var page = 1
    function initFamaTab() {

        if ($.type(famaTable) != 'object') {
            famaTable = $('#tima').find('table[data-ride="datatables"]').DataTable({
                "ajax": {
                    url: "sendCode/queryBatchDetailPage?batchId=" + batchId,
                    type: "post",
                },
                "processing": true,
                "serverSide": true,
                "autoWidth": true,
                "searchDelay": 500,
                "displayStart": parseInt(page) * 10 - 10,
                "pagingType": "full_numbers",
                "pageLength": 10,
                "dom": "<'row'<'col col-lg-6'l><'col col-lg-6'f>r>t<'row'<'col col-lg-6'i><'col col-lg-6'p>>",
                "aaSorting": [[3, "desc"]],//默认排序
                "columns": [
                    {"data": "code", "name": "code", "width": "70px"},
                    {"data": "customerMobile", "name": "customerMobile", "width": "90px", "sortable": false},
                    {"data": "createtime", "name": "createtime", "width": "170px", "sortable": false},
                    {"data": "status", "name": "status", "className": "name", "width": "100px"},
                    {"data": "remark", "name": "remark", "width": "180px"},
                    {"data": null, "width": "170px"}
                ],
                "columnDefs": [
                    {"searchable": false, "targets": [3]},
                    // 状态，状态暂定为01：已提码，02：已导入，03：已送码，未发码，04：已发码
                    {
                        "targets": 3,
                        "data": "status",
                        "sortable": false,
                        "render": function (data, type, full) {
                            //  batch 00：已删除 01：已提码，未导入联系人  02：已导入联系人，待送码  03：已送码，待发码 04：已发码
                            var statusText;
                            if (data == "01") {
                                statusText = "已提码";
                            }
                            if (data == "02") {
                                statusText = "已导入";
                            }
                            if (data == "03") {
                                statusText = "已送码，未发码";
                            }
                            if (data == "04") {
                                statusText = "已发码";
                            }
                            return statusText;
                        }
                    },
                    {
                        "targets": 5,
                        "data": null,
                        "sortable": false,
                        "render": function (data, type, full) {
                            if (tp == "02") {
                                return '<a href="javascript:sendCode(\'' + data['id'] + '\')" >发送短信</a>';
                            }
                            if (tp == "03") {
                                return '<a href="javascript:sendCodeMMS(\'' + data['id'] + '\')">彩信发码</a>';
                            }
                            if (tp.indexOf("02") >= 0 && tp.indexOf("03") >= 0) {
                                return '<a href="javascript:sendCode(\'' + data['id'] + '\')" >发送短信</a>' +
                                        '<a href="javascript:sendCodeMMS(\'' + data['id'] + '\')">彩信发码</a>';
                            }
                        }
                    }
                ]
            });
        }
    }
</script>
<script>
    if (tp == "02") {
        $("#allSend").removeAttr("style");
    }
    if (tp == "03") {
        $("#allMMSSend").removeAttr("style");
    }
    if (tp.indexOf("02") >= 0 && tp.indexOf("03") >= 0) {
        $("#allSend").removeAttr("style");
        $("#allMMSSend").removeAttr("style");
    }
</script>
<script>
    $("#allSend").click(function () {
        $.get("sendCode/sendCodeByBatchId", {"actId": actId, "batchId": batchId, "type": "02"}, function (result) {
            if (result.success) {
                sendMsg(true, "发送短信成功");
                window.location.reload();
            } else {
                sendMsg(false, result.errorMsg);
                window.location.reload();
            }
        }, 'json');
    });
    $("#allMMSSend").click(function () {
        $.get("sendCode/sendCodeByBatchId", {"actId": actId, "batchId": batchId, "type": "03"}, function (result) {
            if (result.success) {
                sendMsg(true, "发送彩信成功");
                window.location.reload();
            } else {
                sendMsg(false, result.errorMsg);
                window.location.reload();
            }
        }, 'json');
    });
</script>
<script>
    function sendCodeMMS(id) {
        $.get("sendCode/sendCodeById", {"actId": actId, "id": id, "type": "03"}, function (result) {
            if (result.success) {
                sendMsg(true, "发送彩信成功");
                window.location.reload();
            } else {
                sendMsg(false, result.errorMsg);
                window.location.reload();
            }
        }, 'json');
    }
    function sendCode(id) {
        $.get("sendCode/sendCodeById", {"actId": actId, "id": id, "type": "02"}, function (result) {
            if (result.success) {
                sendMsg(true, "发送短信成功");
                window.location.reload();
            } else {
                sendMsg(false, result.errorMsg);
                window.location.reload();
            }
        }, 'json');
    }
</script>
</body>
</html>
                